// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.

using System.IO;

namespace UnrealBuildTool.Rules
{
    public class NVIDIAGfeSDK : ModuleRules
    {
        private string ModulePath
        {
            get { return ModuleDirectory; }
        }

        private string ThirdPartyPath
        {
            get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
        }

        private string BinariesPath
        {
            get { return Path.GetFullPath(Path.Combine(ThirdPartyPath, "NVIDIAGfeSDK", "redist")); }
        }

        private string LibraryPath
        {
            get { return Path.GetFullPath(Path.Combine(ThirdPartyPath, "NVIDIAGfeSDK", "lib")); }
        }

        public NVIDIAGfeSDK(TargetInfo Target)
        {
            PublicIncludePaths.AddRange(
                new string[] {
                "NVIDIAGfeSDK/Public",
                ThirdPartyPath + "NVIDIAGfeSDK/Include",
                ThirdPartyPath + "NVIDIAGfeSDK/Include/gfesdk",
                    // ... add public include paths required here ...
                }
            );

            PrivateIncludePaths.AddRange(
                new string[] {
                "NVIDIAGfeSDK/Private",
                    //Path.Combine(ThirdPartyPath, "NVIDIAGfeSDK", "Include"),
                ThirdPartyPath + "NVIDIAGfeSDK/Include",
                ThirdPartyPath + "NVIDIAGfeSDK/Include/gfesdk",
                    // ... add other private include paths required here ...
                }
            );

            PublicDependencyModuleNames.AddRange(
                new string[]
                {
                    "Engine",
                    "Core",
                    "Projects",
                    "CoreUObject"
                }
            );

            PrivateDependencyModuleNames.AddRange(
                new string[]
                {
                    // ... add private dependencies that you statically link with here ...
                }
            );

            DynamicallyLoadedModuleNames.AddRange(
                new string[]
                {
                    // ... add any modules that your module loads dynamically here ...
                }
            );

            LoadNVIDIAGfeSDKLib(Target);
        }

        public bool LoadNVIDIAGfeSDKLib(TargetInfo Target)
        {
            bool isLibrarySupported = false;

            if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))
            {
                isLibrarySupported = true;

                string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "Win64" : "Win32";

                string DllPath = Path.Combine(BinariesPath, PlatformString);                
                string LibFullPath = Path.Combine(LibraryPath, PlatformString);

                string DllName = Path.Combine(DllPath, "GfeSDK.dll");
                string LibFilePath = Path.Combine(LibFullPath, "GfeSDK.lib");

                PublicLibraryPaths.Add(LibFullPath);
                PublicAdditionalLibraries.Add("GfeSDK.lib");

                PublicDelayLoadDLLs.Add("GfeSDK.dll");
                RuntimeDependencies.Add(new RuntimeDependency(DllName));
            }

            return isLibrarySupported;
        }
    }
}
